#!/bin/bash
set -e
test -d script || mkdir script
rm -rf script/shadowsocks
test -d  /etc/shadowsocks.json && rm /etc/shadowsocks.json
mkdir script/shadowsocks
echo -e  "#!/bin/bash
ssserver -c /etc/shadowsocks.json -d start">script/shadowsocks/start.sh

echo -e "#!/bin/bash
ssserver -c /etc/shadowsocks.json -d stop">script/shadowsocks/stop.sh

echo -e "#!/bin/bash
ssserver -c /etc/shadowsocks.json -d stop
pip uninstall shadowsocks -y
rm /etc/shadowsocks.json
rm -rf ../shadowsocks">script/shadowsocks/uninstall.sh

yum install -y python-setuptools && easy_install pip
pip install shadowsocks

arg=`cat config.json | awk -F "[:]" '/ip/{print$2}'`

echo "{\"ip\":$arg,
        \"server_port\":8388,
        \"local_address\":\"127.0.0.1\",
        \"local_port\":1080,
        \"password\":\"Aa49810712\",
        \"timeout\":300,
        \"method\":\"aes-256-cfb\",
        \"fast_open\":false
}"> /etc/shadowsocks.json

ssserver -c /etc/shadowsocks.json -d start
